package com.yanqu.road.server.cmd.activity.recallplayer;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = CrossProtocol.C_PLAYER_RECALL_UPDATE_RETURN_USER_INFO_RESP, desc = "更新玩家数据返回跨服")
public class CrossUpdateBindUserInfoRespCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        RecallPlayerProto.RecallPlayerGetUserInfoResp msg = RecallPlayerProto.RecallPlayerGetUserInfoResp.parseFrom(yanQuMessage.getBytes());
        RecallPlayerProto.RecallPlayerCrossGetUserInfoResp.Builder respMsg = RecallPlayerProto.RecallPlayerCrossGetUserInfoResp.newBuilder();
        respMsg.setRet(msg.getRet());
        respMsg.setRecallUserId(msg.getRecallUserId());
        respMsg.setOperation(msg.getOperation());
        if (msg.hasUserInfo()) {
            respMsg.setUserInfo(msg.getUserInfo());
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_RECALL_PLAYER_UPDATE_USER_INFO_RESP, respMsg);
        MessageHelper.sendPacket(msg.getFromUserServer(), msg.getFromUserId(), message);
    }
}
